<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>

</body>
</html>
<script type="text/javascript">
// 排序1
var arr=[23,24,64,4,6,35,65,12];
console.log(arr);
for(var i=0;i<arr.length;i++){
  for(var j=0;j<arr.length;j++){
    if(arr[j]>arr[j+1]){
      var c=arr[j+1];
      arr[j+1]=arr[j];
      arr[j]=c;
    }
  }
}
console.log(arr);
// 排序2
var arr=[34,23,43,21,12,26,65,4];
console.log(arr);
for(var i=0;i<arr.length;i++){
  // 设置当前范围的最小值和索引
  var min =arr[i];
  var minIndex=i;
  for(var j=i+1;j<arr.length;j++){
    if(min>arr[j]){
      min=arr[j];
      minIndex=j;
    }
  }
  arr.splice(i,0,min);
  arr.splice(minIndex+1,1);
}
console.log(arr);

// 去重1
var arr=[2,3,54,3,6,3,56,32,45,2,54];
var newArr=[];
for (var i = 0; i <arr.length; i++) {
  if(newArr.indexOf(arr[i])==-1){
    newArr.push(arr[i]);
  }
}
console.log(arr);
console.log(newArr);
// 去重2
function sort(ar){
  var res=[];
  var arr1={};
  for(var i=0;i<ar.length;i++){
    if(!arr1[ar[i]]){
      arr1[ar[i]]=1;
      res.push(ar[i]);
    }
  }
  return res;
}
  var arr=[34,23,53,53,23,12,43,22,12,64,2,4,22];
  console.log(arr);
  console.log(sort(arr));
</script>
